package com.tongzhan.controller;

import com.tongzhan.base.Return;
import com.tongzhan.entity.User;
import com.tongzhan.entity.party.PeopleOpinion;
import com.tongzhan.entity.xiangxian.ExamplePoint;
import com.tongzhan.service.DangpaiService;
import com.tongzhan.vo.PersonDetailVO;
import com.tongzhan.vo.UserInfoVO;
import io.micrometer.core.instrument.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.awt.print.Pageable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 党派
 */
@RequestMapping("/dangpai")
@RestController
public class DangpaiController {

    @Autowired
    private DangpaiService dangpaiService;

    /**
     * 获取党派大屏地图列表，即示范点数据列表
     *
     * @return
     */
    @RequestMapping("/getMapList")
    public Return getMapList(Integer type, String date) {
        Map<String, Object> map = new HashMap<>();
        List<ExamplePoint> list = dangpaiService.getMapList(type, date);
        map.put("list", list);
        return Return.getSuccessResult(map);
    }

    /**
     * 获取党派社情民意列表
     *
     * @return
     */
    @RequestMapping("/getPeopleOpinionList")
    public Return getPeopleOpinionList(Integer type, String date) {
        Map<String, Object> map = new HashMap<>();
        List<PeopleOpinion> list = dangpaiService.getPeopleOpinionList(type, date);
        map.put("list", list);
        return Return.getSuccessResult(map);
    }

    /**
     * 获取党派新成员统计
     *
     * @param type
     * @param date
     * @return
     */
    @RequestMapping("/getNewPersonList")
    public Return getNewPersonList(Integer type, String date) {
        Map<String, Object> map = dangpaiService.getNewPersonList(type, date);
        return Return.getSuccessResult(map);
    }

    /**
     * 获取党派活动中心统计
     *
     * @param type
     * @param date
     * @return
     */
    @RequestMapping("/getActionCenterList")
    public Return getActionCenterList(Integer type, String date) {
        Map<String, Object> map = dangpaiService.getActionCenterList(type, date);
        return Return.getSuccessResult(map);
    }

    /**
     * 获取党派社情民意统计
     *
     * @param type
     * @param date
     * @return
     */
    @RequestMapping("/getParticipationList")
    public Return getParticipationList(Integer type, String date) {
        Map<String, Object> map = dangpaiService.getParticipationList(type, date);
        return Return.getSuccessResult(map);
    }

    /*===========================================2.0版本============================================*/

    /**
     * 人员统计（每个街道对应人数）
     *
     * @return
     */
    @RequestMapping("/personCount")
    public Return personCount(String streetCode,String villageCode) {
        List<UserInfoVO> list = dangpaiService.personCount(streetCode,villageCode);
        return Return.getSuccessResult(list);
    }

    /**
     * 人员统计详情（所有人员的个人信息）
     *
     * @return
     */
    @RequestMapping("/personDetail")
    public Return personDetail(String streetCode,String villageCode) {
        List<PersonDetailVO> list = dangpaiService.personDetail(streetCode,villageCode);
        return Return.getSuccessResult(list);
    }

    /**
     * 活动中心统计
     *
     * @return
     */
    @RequestMapping("/actionCenterCount")
    public Return actionCenterCount(String streetCode,String villageCode) {
        return Return.getSuccessResult(dangpaiService.actionCenterCount(streetCode,villageCode));
    }

    /**
     * 活动中心统计详情
     *
     * @return
     */
    @RequestMapping("/actionCenterDetail")
    public Return actionCenterDetail(String streetCode,String villageCode) {
        return Return.getSuccessResult(dangpaiService.actionCenterDetail(streetCode,villageCode));
    }

    /**
     * 社情名义统计
     *
     * @return
     */
    @RequestMapping("/opinionCount")
    public Return opinionCount(String streetCode,String villageCode) {
        return Return.getSuccessResult(dangpaiService.opinionCount(streetCode,villageCode));
    }

    /**
     * 社情名义统计详情
     *
     * @return
     */
    @RequestMapping("/opinionDetail")
    public Return opinionDetail(String streetCode,String villageCode) {
        return Return.getSuccessResult(dangpaiService.opinionDetail(streetCode,villageCode));
    }

    /**
     * 发展成员统计
     *
     * @return
     */
    @RequestMapping("/newPeopleCount")
    public Return newPeopleCount(String streetCode,String villageCode) {
        return Return.getSuccessResult(dangpaiService.newPeopleCount(streetCode,villageCode));
    }

    /**
     * 发展成员统计详情
     *
     * @return
     */
    @RequestMapping("/newPeopleDetail")
    public Return newPeopleDetail(String streetCode,String villageCode) {
        return Return.getSuccessResult(dangpaiService.newPeopleDetail(streetCode,villageCode));
    }

    /**
     * 获取党派分类
     *
     * @return
     */
    @GetMapping("/getPartyType")
    public Return getPartyType() {
        return Return.getSuccessResult(dangpaiService.getPartyType());
    }

    /**
     * 获取党派列表
     *
     * @param type
     * @return
     */
    @GetMapping("/getPartyinfoList")
    public Return getPartyinfoList(Integer type) {
        if (type == null || type < 0) {
            return Return.getErrorResult("缺少参数");
        }
        return Return.getSuccessResult(dangpaiService.getPartyinfoList(type));
    }

    @PostMapping("/addPartyinfo")
    public Return addPartyinfo(String name, String address, String introduction, String picture, String latitude, String longitude, Integer type) {
        if (StringUtils.isBlank(name) || StringUtils.isBlank(address) || StringUtils.isBlank(introduction) ||
                StringUtils.isBlank(picture) || StringUtils.isBlank(latitude) || StringUtils.isBlank(longitude) ||
                type == null || type < 0) {
            return Return.getErrorResult("缺少参数");
        }
        Integer l = dangpaiService.addPartyinfo(name, address, introduction, picture, latitude, longitude, type);
        if (l > 0) {
            return Return.getSuccessResult("新增成功!");
        }
        return Return.getErrorResult("新增失败!");
    }

}
